<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
		function createCache() {
			var keys = [];
			function cache(key,value) {
				// 使用(key + “”) 是为了避免和原生(本地)的原型中的属性冲突
				if(keys.push(key+" ") > 3) {
					// 只保留新存入的数据
					delete cache[keys.shift()];
				}
				// 1.给cache赋值
				// 2.把值返回
				return (cache[key + " "] = value);
			}
			return cache;
		}

        var typeCache = createCache();
        typeCache("monitor");
        console.log(typeCache["monitor" + " "]);

        typeCache("monitor1","张学友");
        console.log(typeCache["monitor1" + " "]);

        typeCache("monitor2","刘德华");
        console.log(typeCache["monitor2" + " "]);

        typeCache("monitor3","彭于晏");
        console.log(typeCache["monitor3 "]);
		
		typeCache("monitor4","郭富城");
		console.log(typeCache["monitor1 "]);
		console.log(typeCache["monitor4 "]);


//        console.log(typeCache["monitor "]);

    </script>
</head>
<body>

</body>
</html>